package com.jjb.www.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.hjq.shape.layout.ShapeLinearLayout;
import com.hjq.shape.layout.ShapeRecyclerView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.AnsweringDetailsApi;
import com.jjb.www.ui.activity.AnsweringDetailsActivity;
import com.jjb.www.ui.activity.ErrorPostActivity;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class AnsweringDetailsAdapter extends AppAdapter<AnsweringDetailsApi.Bean> {
    private AansweringDetails2Adapter adapter;
    private AansweringDetails3Adapter adapter3;
    public AnsweringDetailsAdapter(Context context) {
        super(context);
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeTextView mTvTitle;
        private ShapeRecyclerView mRvQuestion;
        private ShapeRecyclerView mRvQuestionZh;
        private ShapeTextView mTvIsTrue;
        private ShapeTextView mTvTrueAnswer;
        private ShapeTextView mTvAnswer;
        private ShapeLinearLayout mLlItemView;
        private ShapeLinearLayout mLlError;






        private ViewHolder() {
            super(R.layout.item_answering_details);
            mTvTitle = findViewById(R.id.tv_title);
            mRvQuestion = findViewById(R.id.rv_question);
            mRvQuestionZh = findViewById(R.id.rv_question_zh);
            mTvIsTrue = findViewById(R.id.tv_is_true);
            mTvTrueAnswer = findViewById(R.id.tv_true_answer);
            mTvAnswer = findViewById(R.id.tv_answer);
            mLlError = findViewById(R.id.ll_error);
            mLlItemView = findViewById(R.id.ll_item_view);
            adapter = new AansweringDetails2Adapter(getContext());
            adapter3 = new AansweringDetails3Adapter(getContext());
            mRvQuestion.setLayoutManager(new LinearLayoutManager(getContext()));
            mRvQuestionZh.setLayoutManager(new LinearLayoutManager(getContext()));
            mRvQuestion.setAdapter(adapter);
            mRvQuestionZh.setAdapter(adapter3);
            setIsRecyclable(false);
        }

        @Override
        public void onBindView(int position) {
            AnsweringDetailsApi.Bean bean = getItem(position);

            mLlError.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.putExtra("paperId", AnsweringDetailsActivity.PaperId);
                    intent.putExtra("type",bean.getType()+"");
                    intent.putExtra("question_id",bean.getQuestion_id()+"");
                    intent.putExtra("order_number",bean.getOrder_number()+"");
                    intent.putExtra("question_type",bean.getQuestion_type()+"");
                    intent.setClass(getContext(), ErrorPostActivity.class);
                    getContext().startActivity(intent);
                }
            });
            if (bean.getQuestion_type()==2){
                //综合题
                mLlItemView.setVisibility(View.GONE);
                mRvQuestion.setVisibility(View.GONE);
                mRvQuestionZh.setVisibility(View.VISIBLE);
                adapter3.setItemSel(bean.getOrder_number()+"",bean.getQuestion_type()+"");
                adapter3.setTag(bean.getAnswer_sort());
                adapter3.setData(bean.getQuestion_son_list());
                mTvTitle.setText((position+1)+"、"+bean.getBackground_title());
            }else {
                mLlItemView.setVisibility(View.VISIBLE);
                mRvQuestion.setVisibility(View.VISIBLE);
                mRvQuestionZh.setVisibility(View.GONE);
                adapter.setTag(bean.getAnswer_sort());
                adapter.setData(bean.getQuestion_answer());
                mTvTitle.setText((position+1)+"、"+bean.getTitle());
                //非综合题


                if (( bean.getIs_true()==1)){
                    //答题正确
                    mTvIsTrue.setText("作答正确");
                    mTvIsTrue.getTextColorBuilder()
                            .setTextColor(ContextCompat.getColor(getContext(), R.color.color_09BB07))
                            .intoTextColor();
                }else {
                    //作答错误
                    mTvIsTrue.setText("作答错误");
                    mTvIsTrue.getTextColorBuilder()
                            .setTextColor(ContextCompat.getColor(getContext(), R.color.color_E34D59))
                            .intoTextColor();
                }
                mTvTrueAnswer.setText("正确答案："+bean.getTrue_answer());
                if ("".equals(bean.getAnswer())){
                    mTvAnswer.setVisibility(View.GONE);
                }else {
                    mTvAnswer.setVisibility(View.VISIBLE);
                    mTvAnswer.setText("答题解析:"+bean.getAnswer());
                }
            }

        }
    }
}